$(function () {
    initLayDate();
    //显示积分规则
    var showIntegral = function () {
        var flag = false;
        $('#showGetIntegralBtn').on('click', function () {
            if(!flag) {
                $('#u-getIntegral-box').show();
                flag = true;
            } else {
                $('#u-getIntegral-box').hide();
                flag = false;
            }
        });
    }
    showIntegral();
    queryUserAccountHistories(1);
    openRecharge();
    $("body").on('click',".select-price",function () {
        var _this = $(this);
        var price = _this.find("a").data('price');
        userPayAccount(price);
    }).on('click',".in-price-but",function () {
        var price = $("#input-price").val();
        userPayAccount(price);
    }).on('click',".new-in-price-but",function () {
        var price = $(this).prev().val();
        userPayAccount(price);
    }).on('click','#search-btn',function () {//账户变动记录类型
        queryUserAccountHistories(1);
    }).on('click',"#setPayCode",function () {
        icModale(0,'','新版功能即将上线,敬请期待...');
    });

    /**
     * 跳转账户充值
     * @param price 充值金额
     */
    function userPayAccount(price) {
        var reg = /^[0-9]+$/;
        if($.trim(price)==null || !reg.test(price) || price<=0 || price>9999){
            icModale(0,'','账户充值金额必须是正整数，且大于0小于9999');
            return;
        }
        window.location.href = baseloaction +'/web/uc/order/initPayOrder?orderType=ACCOUNT&shopData=0-ACCOUNT-'+price;
    }

    /**
     * 立即充值
     */
    function openRecharge() {
        $('body').on('click', '#recharge', function() {
            var _ele = $('#achangeEle1').html();
            layer.open({
                type: 1,
                title: '充值列表',
                shadeClose: true,
                skin: 'lay_ppComment__wrap',
                area: ['635px', '275px'],
                content: _ele,
                success: function (index, layero) {
                }
            });
        });
    }
});

/**
 * 获取账户变化列表页面
 * @param pageNo 当前页码
 */
function queryUserAccountHistories(pageNo) {
    var _params={
        actHistoryType : $("#accountHistoryType").val(),
        startTime:$("#beginTime").val(),
        endTime:$("#endTime").val()
    };
    _params = JSON.stringify(_params);
    getPageAjaxData({
        url: baseloaction + '/web/uc/ajax/queryUserAccountHistories',
        contextId:'account-list-context',
        pageNo:pageNo,
        pageCall:queryUserAccountHistories,
        params:_params,
        callback:function (pageNo) {
        }
    });
}

/**
 * 初始化时间插件
 */
function initLayDate() {
    laydate({
        elem: '#beginTime',
        format: 'YYYY-MM-DD hh:mm:ss',
        istime: true,
        choose: function (datas) {
            end.min = datas; //开始日选好后，重置结束日的最小日期
            end.start = datas //将结束日的初始值设定为开始日
        }
    });
    laydate({
        elem: '#endTime',
        format: 'YYYY-MM-DD hh:mm:ss',
        istime: true,
        choose: function (datas) {
            start.max = datas; //结束日选好后，重置开始日的最大日期
        }
    });
}
